
package cn.afactory.tygz.ui.base.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.harwkin.nb.camera.BaseImgView;
import com.lidroid.xutils.http.client.multipart.content.StringBody;
import com.nostra13.universalimageloader.core.assist.ImageScaleType;

import java.util.ArrayList;
import java.util.List;

import cn.afactory.tygz.R;
import cn.afactory.tygz.model.SnsUserInfo;
import cn.afactory.tygz.ui.base.utils.ImageUtils;
import cn.afactory.tygz.ui.base.utils.sns.ViewListener;

public class SubjectAgreeUserGirdAdapter extends BaseAdapter {

    private Context mContext;
    LayoutInflater inflater = null;

    List<SnsUserInfo> mPath = new ArrayList<SnsUserInfo>();
    int mHeight = 0, mWidth = 0;
    public ViewListener mListener;

    public SubjectAgreeUserGirdAdapter(Context context,
                                       List<SnsUserInfo> pics, int Width, int Height) {
        mContext = context;
        mPath = pics;
        inflater = LayoutInflater.from(context);
        mWidth = Width;
        mHeight = Height;
    }

    @Override
    public int getCount() {
        if (mPath != null) {
            return mPath.size();
        }
        return 0;
    }

    @Override
    public Object getItem(int position) {
        if (mPath != null && mPath.size() > 0) {
            return mPath.get(position);
        }
        return null;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }


    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if (convertView == null) {
            convertView = LayoutInflater.from(mContext).inflate(R.layout.list_item_icon_grid, null);
            viewHolder = new ViewHolder();
            viewHolder.list_item_img = (ImageView) convertView.findViewById(R.id.forum_iv);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder)convertView.getTag();
        }

        String iconUrl = mPath.get(position).userIcon;

        try {
            if (!TextUtils.isEmpty(iconUrl)) {
                BaseImgView.loadimg(viewHolder.list_item_img,
                        iconUrl,
                        R.drawable.ic_pic_loading_default_small,
                        R.drawable.ic_pic_loading_default_small,
                        R.drawable.ic_pic_loading_default_small,
                        ImageScaleType.EXACTLY,
                        (int) mContext.getResources().getDimension(R.dimen.healthcircle_padding30),
                        (int) mContext.getResources().getDimension(R.dimen.healthcircle_padding30),
                        20);
//                viewHolder.list_item_img.setScaleType(ImageView.ScaleType.CENTER_CROP);
//                String str = iconUrl.toLowerCase();
////                int nwidth = mWidth > 0 ? mWidth : mContext.getResources().getDimensionPixelOffset(R.dimen.tv_scan_margin_top);
//                int nwidth = 36;
//                BaseImgView.loadimg(viewHolder.list_item_img, ImageUtils.getThumbnailFullPath(iconUrl,
//                                nwidth + "x" +
//                                        nwidth), R.drawable.ic_pic_loading_default_small,
//                        R.drawable.ic_pic_loading_default_small, R.drawable.ic_pic_loading_default_small, ImageScaleType.EXACTLY,
//                        nwidth,
//                        nwidth, 0);
//                if (mListener != null) {
//                    mHolder.list_item_img.setOnClickListener(new View.OnClickListener() {
//                        @Override
//                        public void onClick(View v) {
//                            mListener.onClick(position, mPath);
//                        }
//                    });
//                }
            } else {
                viewHolder.list_item_img.setImageResource(R.drawable.ic_pic_loading_default_small);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return convertView;
    }

    public final class ViewHolder {
        ImageView list_item_img;
    }

    public List<SnsUserInfo> getData() {
        return mPath;
    }

    public void setListener(ViewListener listener) {
        mListener = listener;
    }
}
